<?php
require_once 'lvmao_func.php';


//用户购买收费信息浏览权限
function BuyInfo($contentid)
{
	global $db;
	$uid=GetId();
	
	$sql="select needscore from ".DB_PRE."c_qxnews where contentid=".$contentid;
	$re=$db->query($sql);
	$re=$db->fetch_array($re);
	$needscore=$re[needscore];
	$needscore=0-$needscore;
	
	
	return AddScoreLog($uid,$needscore,1,$contentid,0,"");
}



//检查用户是否有权限查看收费信息
function CheckInfo($contentid)
{
	global $db;
	global $_groupid;
	$uid=GetId();
	
	//是游客则无权限
	if($uid=="0")
	{
		return false;
	}
	
	//是管理员则直接通过
	if($_groupid==1)
	{
		return true;
	}
	
	//不是管理员需要判断是否有效企业用户
	$sql="select a.level as lv from company a inner join r_company_user b on a.id=b.cid and b.uid=".$uid." and b.state=1";
	//echo $sql."-".$_groupid;
	
	$re=$db->query($sql);
	
	if($db->num_rows($re)==1)
	{
		$re=$db->fetch_array($re);
		
		//echo $re[lv];
		
		if($re[lv]==1)
		{
			return true;
		}
	}
	
	//是否单独购买过该篇文章
	$sql="select count(id) as countx from score_log where uid=".$uid." and typeid=1 and objid=".$contentid;
	//echo $sql;
	
	$re=$db->query($sql);
	
	$re=$db->fetch_array($re);
	
	if($re[countx]>0)
	{
		return true;
	}
	
	return false;
}
?>